package com.arnold.service;

import com.arnold.entity.ResponseData;
import com.arnold.entity.goods.Goods;
import com.arnold.entity.goods.PageBean;
import com.arnold.goods.GoodsService;
import com.arnold.mapper.GoodsMapper;
import com.arnold.pay.PayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by arnold.zhu on 2017/9/26.
 */
@Service("GoodsService")
@Transactional
public class GoodsServiceImpl implements GoodsService {

    private Logger logger = LoggerFactory.getLogger(GoodsServiceImpl.class);

    @Autowired
    private PayService payService;

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public ResponseData buyGoods(Goods goods) {
        int num = goodsMapper.updateGoods(goods);
        String payInfo = payService.pay();
        logger.info(num + "-" + payInfo);
        return new ResponseData(200, "Buy_Success!");
    }

    @Override
    public ResponseData findItemByPage(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Goods> goods = goodsMapper.findAll();
        PageInfo<Goods> pageInfo = new PageInfo<>(goods);
        logger.info(pageInfo.getList().size() + "");
        return new ResponseData(200, "Find_Success!", pageInfo);
    }
}
